home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / dev / amos / AMCAFExa.lha / AMCAF_Examples / VecRotSolidGlenz.AMOS / VecRotSolidGlenz.amosSourceCode
Encoding:
AMOS Source Code  |  1996-01-17  |  3.6 KB  |  134 lines

  1. ' ************************************* Commands used: 
  2. ' *                                   * Vec Rot Pos        Blitter Clear 
  3. ' *           Amcaf Examples          * Vec Rot Angles     =Qsin 
  4. ' *  Vector Rotate Solid+Glenz V1.1   * Vec Rot Precalc
  5. ' *      Written by Chris Hodges      * =Vec Rot X 
  6. ' *                                   * =Vec Rot Y 
  7. ' ************************************* =Vec Rot Z 
  8. '                          
  9. ' Kill the mouse 
  10. Hide 
  11. ' Setup a nice little screen with double buffering 
  12. Screen Open 0,320,256,4,Lowres
  13. Curs Off : Flash Off : Paper 0 : Pen 1 : Cls 
  14. Palette $40,$8C8,$484,$AFA
  15. Double Buffer 
  16. Autoback 0
  17. ' Read out, how many coords are used.
  18. Restore COORDS
  19. Read NUMCO
  20. ' Dim one field to keep these coords, and a second for the rotated.
  21. Dim CO(NUMCO,2),RC(NUMCO,1)
  22. ' Now read all coords in.
  23. For A=1 To NUMCO
  24.   Read CO(A,0),CO(A,1),CO(A,2)
  25. Next 
  26. ' Then, get the number of shapes the object consists of. 
  27. Restore SHAPES
  28. Read NUMLI
  29. ' Dim a field to hold the three coords.  
  30. Dim LI(NUMLI,2)
  31. ' Get the datas. 
  32. For A=1 To NUMLI
  33.   Read LI(A,0),LI(A,1),LI(A,2)
  34. Next 
  35. ' Set the three angles. Remember that these are non standard angles, 
  36. ' one full rotation is at 1024, not 360! 
  37. AX=0 : AY=512 : AZ=128
  38. Repeat 
  39.   ' Start clearing bitplane 0. 
  40.    Extension_8_121C 0,0
  41.   ' While the blitter is working, use the time to calculate the rotations. 
  42.   ' Move and set the angles. 
  43.   Add AX,4
  44.   Add AY,7
  45.   Add AZ,24
  46.    Extension_8_1138 AX,AY,AZ
  47.   ' Calculate the distances by using a sine-function and the three angles. 
  48.   POSX= Extension_8_1106(AX,300)
  49.   POSY= Extension_8_1106(AY,300)
  50.   POSZ= Extension_8_1106(AZ,500)+1500
  51.   ' Set the camera positions.
  52.    Extension_8_1122 POSX,POSY,POSZ
  53.   ' Now it's time to compute the matrix. 
  54.    Extension_8_1152 
  55.   ' Clear bitplane 1 
  56.    Extension_8_121C 0,1
  57.   ' So let's rotate all coordinates of the field CO()
  58.   For A=1 To NUMCO
  59.     ' Note: You only have to use the vec rot function with parameters once.
  60.     RC(A,0)= Extension_8_1168(CO(A,0),CO(A,1),CO(A,2))+160
  61.     RC(A,1)= Extension_8_1184 +128
  62.   Next 
  63.   ' It's time to finally get the polygons to the screen! 
  64.   For A=1 To NUMLI
  65.     ' Get the three coordinates pairs.   
  66.     C1=LI(A,0) : C2=LI(A,1) : C3=LI(A,2)
  67.     ' Get the rotated coordinates
  68.     X1=RC(C1,0) : Y1=RC(C1,1)
  69.     X2=RC(C2,0) : Y2=RC(C2,1)
  70.     X3=RC(C3,0) : Y3=RC(C3,1)
  71.     ' Use some maths, to see if the plane faces into the camera or into
  72.     ' the back. This formula works ONLY, if the polygon is drawn 
  73.     ' anticlockwise!   
  74.     DI=(X3-X1)*(Y2-Y1)-(X2-X1)*(Y3-Y1)
  75.     If DI<0
  76.       ' Draw the polygons in bitplane 1  
  77.        Extension_8_1016 X1,Y1 To X2,Y2,2,-2
  78.        Extension_8_1016 X2,Y2 To X3,Y3,2,-2
  79.        Extension_8_1016 X3,Y3 To X1,Y1,2,-2
  80.     Else 
  81.       ' Draw the polygons in bitplane 0  
  82.        Extension_8_1016 X1,Y1 To X2,Y2,1,-1
  83.        Extension_8_1016 X2,Y2 To X3,Y3,1,-1
  84.        Extension_8_1016 X3,Y3 To X1,Y1,1,-1
  85.     End If 
  86.   Next 
  87.   ' Fill both bitplanes. 
  88.    Extension_8_1042 0,0
  89.    Extension_8_1042 0,1
  90.   ' Swap the screens to bring the object to view.
  91.   Screen Swap 
  92.   Wait Vbl 
  93. Until Inkey$=Chr$(27) or Mouse Key<>0
  94. Screen Close 0
  95. End 
  96. '  1_____2   
  97. ' 5/____/| 
  98. ' | |  |6| 
  99. ' |4|__|_|3  
  100. ' |/___|/
  101. ' 8    7 
  102. COORDS:
  103.   Data 14
  104. ' POLYEDER 
  105.   Data -100,-100,-100
  106.   Data 100,-100,-100
  107.   Data 100,-100,100
  108.   Data -100,-100,100
  109.   Data -100,100,-100
  110.   Data 100,100,-100
  111.   Data 100,100,100
  112.   Data -100,100,100
  113.   Data 0,-175,0
  114.   Data 175,0,0
  115.   Data 0,175,0
  116.   Data -175,0,0
  117.   Data 0,0,175
  118.   Data 0,0,-175
  119.  
  120. SHAPES:
  121.   Data 12
  122. ' All lines are drawn in anticlockwise.
  123.   Data 1,9,4
  124.   Data 2,3,9
  125.   Data 11,7,6
  126.   Data 5,8,11
  127.   Data 4,3,13
  128.   Data 8,13,7
  129.   Data 14,2,1
  130.   Data 6,14,5
  131.   Data 2,6,10
  132.   Data 3,10,7
  133.   Data 12,5,1
  134.   Data 8,12,4